#include "../server.hpp"

void OnMessage(const PtrConnection& conn, Buffer* buf)
{
    DBG_LOG("%s", buf->ReaderPosition());
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "hello world";
    conn->Send(str.c_str(), str.size());
    //conn->Shutdown();
} 
void OnClosed(const PtrConnection& conn)
{
    DBG_LOG("Close Connecion: %p", conn.get());
} 
void OnConnected(const PtrConnection& conn)
{
    DBG_LOG("New Connection: %p", conn.get());
}
int main()
{
    TcpServer server(8080);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(10);

    server.SetClosedCallback(OnClosed);
    server.SetConnectedCallback(OnConnected);
    server.SetMessageCallback(OnMessage);
    
    server.Start(); 
    return 0;
}